/*
 * LongParameterDeployer.java July 2009
 *
 * Copyright (C) 2009, Quirino Zagarese <quirino@laszloitalia.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 */
package org.eu4ria.core.annotations;

import javassist.bytecode.annotation.Annotation;
import javassist.bytecode.annotation.BooleanMemberValue;
import javassist.bytecode.annotation.LongMemberValue;

import org.eu4ria.parameters.LongParameterValidator;

public class LongParameterDeployer {

	private long minvalue = Long.MIN_VALUE;

	private long maxvalue = Long.MAX_VALUE;

	private boolean includeMax = true;

	private boolean includeMin = true;

	public LongParameterValidator deploy(Annotation annotation) {
		LongParameterValidator range = new LongParameterValidator();

		if (annotation == null) {
			range.setIncludeMax(this.includeMax);
			range.setIncludeMin(this.includeMin);
			range.setMaxvalue(this.maxvalue);
			range.setMinvalue(this.minvalue);
		} else {
			LongMemberValue minvalue = (LongMemberValue) annotation
					.getMemberValue("minvalue");
			if (minvalue != null) {
				range.setMinvalue(minvalue.getValue());
			} else {
				range.setMinvalue(this.minvalue);
			}

			LongMemberValue maxvalue = (LongMemberValue) annotation
					.getMemberValue("maxvalue");
			if (maxvalue != null) {
				range.setMaxvalue(maxvalue.getValue());
			} else {
				range.setMaxvalue(this.maxvalue);
			}

			BooleanMemberValue includeMin = (BooleanMemberValue) annotation
					.getMemberValue("includeMin");
			if (includeMin != null) {
				range.setIncludeMin(includeMin.getValue());
			} else {
				range.setIncludeMin(this.includeMin);
			}

			BooleanMemberValue includeMax = (BooleanMemberValue) annotation
					.getMemberValue("includeMax");
			if (includeMin != null) {
				range.setIncludeMax(includeMax.getValue());
			} else {
				range.setIncludeMax(this.includeMax);
			}
		}

		return range;

	}

}
